<?PHP
global $vbulletin, $db;
if ($vbulletin->options['neots_enable_product']) {
	if($vbulletin->GPC['user']['neots_uid']) {
		$old_uid = $db->query_first("SELECT neots_uid FROM " . TABLE_PREFIX . "user WHERE userid=".$vbulletin->GPC['bb_userid']);
		foreach($vbulletin->GPC['user']['neots_uid'] as $uid) {
			$uidcheck = $db->query_first("SELECT COUNT(neots_uid) FROM " . TABLE_PREFIX . "user WHERE neots_uid LIKE '%$uid%'");
			if ($uidcheck[COUNT(neots_uid)] < 1) {
				$pos = strrpos($uid, '=');
				$pos = strlen($uid) - $pos;
				if($pos === 1)
				$uidsafe = array_merge((array)$uidsafe, (array)$uid);
				else
				eval(standard_error($uid.' is not formatted correctly. Make sure you add an = at the end.'));
			}
			else {
				eval(standard_error('Unique ID is already in use. '.$uid));
			}
			unset($uidcheck);
			$db->free_result($uidcheck);
		}
		$vbulletin->GPC['user']['neots_uid'] = $uidsafe;
		$serialized_neots_uid = serialize($vbulletin->GPC['user']['neots_uid']); 
		$this->do_set('neots_uid', $serialized_neots_uid);
		if ($serialized_neots_uid != $old_uid['neots_uid'])
		$db->query_write("INSERT INTO " . TABLE_PREFIX . "teamspeaklog (teamspeaklogid, dateline, userid, old_uid, new_uid, ipaddress) VALUES (NULL, UNIX_TIMESTAMP(), '".$vbulletin->GPC['bb_userid']."', '".$old_uid['neots_uid']."', '".$serialized_neots_uid."', '".$_SERVER['REMOTE_ADDR']."')");
	}

		$this->validfields['neots_token'] = array(TYPE_INT);
		$this->validfields['neots_uid'] = array(TYPE_NOCLEAN, REQ_NO, VF_METHOD, 'verify_serialized');
}
?>